import { _decorator, Component, Node, Label } from 'cc';
import { LangUtil } from 'LangUtil';
import { PlayerDataMgr, GameEventName } from "PlayerDataMgr";
import { GameEvent } from "../../../eazax-ccc/core/GameEvent";
const { ccclass, property } = _decorator;

@ccclass('PlayerDataComponent')
export class PlayerDataComponent extends Component {
    @property({ type: Label })
    public labelScore: Label;

    @property({ type: Label })
    public labelBonus: Label;

    start() {
        this.onDataChangeScore();
        this.onDataChangeBonus();
    }

    onLoad() {
        GameEvent.on(GameEventName.DataChangeScore, this.onDataChangeScore, this);
        GameEvent.on(GameEventName.DataChangeBonus, this.onDataChangeBonus, this);
    }

    onDataChangeScore() {
        this.labelScore.string = LangUtil.Get("Score") + ":" + PlayerDataMgr.Instance.score;
    }

    onDataChangeBonus() {
        this.labelBonus.string = LangUtil.Get("Bonus") + ":" + PlayerDataMgr.Instance.bonus;
    }

    onDestroy() {
        GameEvent.off(GameEventName.DataChangeScore, this.onDataChangeScore, this);
        GameEvent.off(GameEventName.DataChangeBonus, this.onDataChangeBonus, this);
    }

    update(deltaTime: number) {
        
    }
}

